#include "Object.hpp"
#include <iostream>

void Object::Update()
{
	vertexPositionLocation = glGetAttribLocation(shader -> GetProgram(), "VertexPosition");
	vertexNormalLocation = glGetAttribLocation(shader -> GetProgram(), "VertexNormal");
	FixCamera();
}

void Object::Draw()
{
	//glUseProgram(shader -> GetProgram());
    shader -> Use();
	glEnableVertexAttribArray(vertexPositionLocation);
	glBindBuffer(GL_ARRAY_BUFFER, vertexBufferObject);
	glVertexAttribPointer(
		vertexPositionLocation, // attribute
		3,                 // number of elements per vertex, here (x,y)
		GL_FLOAT,          // the type of each element
		GL_FALSE,          // take our values as-is
		0,                 // no extra data between each position
		0                  // offset of first element
	);
	//glDisableVertexAttribArray(vertexPositionLocation);

	glEnableVertexAttribArray(vertexNormalLocation);
	glBindBuffer(GL_ARRAY_BUFFER, normalsBufferObject);
	glVertexAttribPointer(
		vertexNormalLocation, // attribute
		3,                 // number of elements per vertex, here (x,y)
		GL_FLOAT,          // the type of each element
		GL_FALSE,          // take our values as-is
		0,                 // no extra data between each position
		0                  // offset of first element
	);
	//glDisableVertexAttribArray(vertexNormalLocation);

	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBufferObject);
	int size;

	glGetBufferParameteriv(GL_ELEMENT_ARRAY_BUFFER, GL_BUFFER_SIZE, &size);
	//std::cout << size / sizeof(GLuint) << std::endl;
	glDrawElements(GL_TRIANGLES, size/sizeof(GLuint), GL_UNSIGNED_INT, 0);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
    glDisableVertexAttribArray(vertexPositionLocation);
    glDisableVertexAttribArray(vertexNormalLocation);
	Shader::UseNoShader();
}

void Object::FixCamera()
{

}

void Object::SetColor(Vector3 ColorIn)
{
	color = ColorIn;
}







